<template>
  <div>
    <h3>创作者待审核</h3>
    <el-row class="mb8">
        <el-col :span="1.5">
          
        </el-col>
   
        <right-toolbar @queryTable="get_list"></right-toolbar>
     
    </el-row>
    <el-table :data="tableData" style="width: 100%">
      <!-- <el-table-column prop="id" label="id" width="120"> </el-table-column>
      <el-table-column prop="goodsId" label="goodsid" width="120">
      </el-table-column> -->
      <el-table-column   show-overflow-tooltip label="用户" align="center" prop="username" width="100">
        <template slot-scope="scope">
          <div style="">
            <el-avatar
              :src="scope.row.headimg"
              style="width: 30px; height: 30px"
            ></el-avatar>
            <div>{{ scope.row.username }}</div>
          </div>
        </template>
      </el-table-column>
      <el-table-column align="center" prop="goods.title" label="盒子名称">
      </el-table-column>
      <el-table-column
        align="center"
        prop="goods.imgurl"
        label="封面"
        width="100"
      >
        <template slot-scope="scope">
          <img
            :src="scope.row.goods.imgurl"
            style="width: 60px; height: 60px"
          />
        </template>
      </el-table-column>
      <el-table-column
        prop="goods.price"
        label="价格"
        align="center"
      ></el-table-column>
      <el-table-column align="center" prop="status" label="状态">
        <template slot-scope="scope">
          <el-tag :type="['', 'success', 'info', 'danger'][scope.row.status]">{{
            ["", "已通过", "待审核", "未通过"][scope.row.status]
          }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column
      
        align="center"
        prop="createTime"
        label="日期"
        width="120"
      >
      <template slot-scope="scope">
         {{ parseTime(scope.row.createTime, "{m}-{d} {hh}:{mm}:{ss}") }}
      </template>
      
      </el-table-column>
      <el-table-column fixed="right" align="center" label="操作" width="80">
        <template slot-scope="scope">
          <el-tooltip content="修改状态" placement="top">
            <i
              class="operation el-icon-set-up"
              @click="updataRow(scope.row)"
            ></i>
          </el-tooltip>
          <el-tooltip content=" 查看详情" placement="top">
            <i
              style="margin-left: 20px"
              class="operation el-icon-view"
              @click="look(scope.row)"
            ></i>
          </el-tooltip>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
    @size-change="handleSizeChange"
    @current-change="handleCurrentChange"
    :current-page="page.page"
    :page-sizes="[10, 20, 50, 100]"
    :page-size="page.pageSize"
    :total="total"
    layout="total, sizes, prev, pager, next, jumper"
  ></el-pagination>

    <!-- 弹出窗 -->
    <el-dialog
      title="修改状态"
      :visible.sync="dialogVisible"
      width="30%"
      :beforeClose="handleClose"
    >
      <el-form :model="form" label-width="80px" ref="form">
        <el-form-item label="状态" prop="status">
          <el-radio-group v-model="form.status">
            <el-radio :label="1">通过</el-radio>

            <el-radio :label="3">驳回</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="意见" prop="message">
          <el-input v-model="form.message" type="textarea" rows="3"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="genggai">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { get_list, update_status } from "@/api/czz/index.js";
import { getMy_user } from "@/api/users/user.js";
export default {
  name: "Czz/dai_list",
  data() {
    return {
      tableData: [],
      page: {
        page: 1,
        pageSize: 10,
      },
      loading: false,
      total: 0,
      search: {
        status: 2,
        id: null,
        message: null,
      },
      form: {
        status: 1,
      },
      dialogVisible: false,
    };
  },
  methods: {
    updataRow(row) {
      this.dialogVisible = true;
      this.form.id = row.id;
      // update_status({
      //   id: row.id,
      //   status: row.status == 1 ? 2 : 1,
      // }).then((res) => {
      //   this.get_list();
      // });
    },

    //查询用户信息
    async queryUser(arr) {
      let val = arr;
      for (let index = 0; index < arr.length; index++) {
        console.log(arr[index].userId);
        await getMy_user(arr[index].userId).then((response) => {
          if (response.data) {
            this.$set(
              this.tableData[index],
              "username",
              response.data.nickname
            );
            this.$set(this.tableData[index], "headimg", response.data.headimg);
          }
        });
      }
    },

    genggai() {
      update_status(this.form).then((res) => {
        //消息通知
        if (res.code == 200) {
          this.$message({
            message: "修改成功",
            type: "success",
          });
        }
        this.dialogVisible = false;
        this.get_list();
      });
    },
    get_list() {
      this.loading = true;

      get_list({
        page: this.page.page,
        pageSize: this.page.pageSize,
        ...this.search,
      }).then((res) => {
        this.loading = false;
        this.tableData = res.data.list;
        this.queryUser(this.tableData);
        this.total = res.data.total;
      });
    },
    handleSizeChange(val) {
      this.page.limit = val;
      this.get_list();
    },
    handleCurrentChange(val) {
      this.page.page = val;
      this.get_list();
    },
    handleSearch() {
      this.page.page = 1;
      this.get_list();
    },
    handleReset() {
      this.search = {
        status: 0,
      };
      this.get_list();
    },

    //查看详情
    look(row) {
      const tableId = row.goodsId;
      const tableName = row.goods.title;
      //   const params = { pageNum: this.queryParams.pageNum };
      console.log(row);

      this.$tab.openPage(
        "查看待审核[" + tableName + "]盒子商品详情",
        "/czz/goods_xq/index/" + tableId
      );
    },
  },
  mounted() {
    this.get_list();
  },
};
</script>

<style></style>
